<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <title>首页</title>
  <link rel="stylesheet" href="./loading.css">
</head>

<body>
  <div id="antd-vue-admin-root">
    <app></app>
    <div id="loading-mask">
      <div class="loading-wrapper">
        <span class="loading-dot loading-dot-spin">
          <i></i>
          <i></i>
          <i></i>
          <i></i>
        </span>
      </div>
    </div>
  </div>
  <script type="text/javascript" src="prepare.js"></script>
  <script type="text/javascript">
    function devEnvConfig(isHotReload, hotLoadServer) {
      if (!isHotReload) {
        return;
      }
      require(['vue', 'http-vue-loader', 'vue-hot-load-api'],
        function (Vue, loader, VueHotLoadAPI) {
          // 安装热加载插件
          VueHotLoadAPI.install(Vue, true);
          var socket;
          var userId = new Date().getTime();

          function openSocket() {
            if (typeof (WebSocket) == "undefined") {
              console.log("您的浏览器不支持WebSocket");
            } else {
              console.log("您的浏览器支持WebSocket");
              //实现化WebSocket对象，指定要连接的服务器地址与端口  建立连接
              //等同于socket = new WebSocket("ws://localhost:8888/xxxx/im/25");
              //var socketUrl="${request.contextPath}/im/"+$("#userId").val();
              // var socketUrl = window.__hot_reload_server__ + '/' + userId;
              var socketUrl = hotLoadServer;
              socketUrl = socketUrl.replace("https", "ws").replace("http", "ws");
              console.log(socketUrl);

              if (socket != null) {
                socket.close();
                socket = null;
              }
              socket = new WebSocket(socketUrl);
              //打开事件
              socket.onopen = function () {
                console.log("ws: 热加载服务连接成功");
                //socket.send("这是来自客户端的消息" + location.href + new Date());
              };
              //获得消息事件
              socket.onmessage = function (msg) {
                //发现消息进入开始处理前端触发逻辑1
                // console.log('ws: ' + msg.data);
                try {
                  var data = JSON.parse(msg.data);
                  if (data.name && data.name.endsWith('.vue')) {
                    console.log('ws: 开始重新加载' + data.name + '组件');
                    loader.reload(data.uniqueId, data.path, data.name);
                  }
                } catch (e) {

                }
              };
              //关闭事件
              socket.onclose = function () {
                console.log("ws: websocket已关闭");
              };
              //发生了错误事件
              socket.onerror = function () {
                console.log("ws: websocket发生了错误");
              }
            }
          }
          openSocket();
        });
    }

    compatibilityDetection()
      .then(function() {
        // 配置全局环境变量
        window.__version__ = '2.0.1';
        window.__env__ = 'dev';
        window.__app__ = '/static';
        window.__server_base_url__ = '/admin';
        window.__timeout__ = 180;
        window.__hot_reload__ = true;
        window.__hot_reload_server__ = 'http://127.0.0.1:3001';
      })
      .then(function() {
        var scriptUrls = [
          // './assets/libs/debug/debug.js',
          './assets/libs/requirejs/require.min.js',
          './require-config/index.js',
          './index.js'
        ];

        if(window.navigator.userAgent.indexOf('Edge') > -1) {
          scriptUrls.splice(0, 0, './assets/libs/polyfill/polyfill.min.js')
        }

        scriptUrls = scriptUrls.map(url => url + '?version=' + window.__version__);
        return qwSerialLoadScripts(scriptUrls);
      })
      .then(() => devEnvConfig(window.__hot_reload__, window.__hot_reload_server__))
      .catch(function () {
        var ele = document.getElementById('loading-mask');
        ele.style.display = 'none';
        document.write('对不起，不支持IE，请使用其他非 IE 内核浏览器访问，比如：360、Firefox、Chrome 浏览器');
      });
  </script>
</body>

</html>